from flask import session, request
from flask_restful import Resource, reqparse

from app.models import User, Opinion, db


class SuggestResource(Resource):
    def get(self):
        pass

    def post(self):
        if session['u_name']:
            name = session['u_name']
            user = User.query.filter(User.u_name == name)
            user = user.first()
            content = request.form.get('content')
            opinion = Opinion()
            opinion.content = content
            opinion.o_user_id = user.u_id
            db.session.add(opinion)
            db.session.commit()
            return {'status': 200, 'msg': 'success'}
        else:
            return {'status': 400, 'msg': 'please login'}

    def put(self):
        pass

    def delete(self):
        pass